package com.salt.modules.sys.service;


import com.salt.common.service.CrudService;
import com.salt.common.utils.IdGen;
import com.salt.core.persistence.Page;
import com.salt.modules.sys.entity.BackgroundImageFiles;
import com.salt.modules.sys.mapper.BackgroundImageFilesMapper;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;

import javax.annotation.Resource;

/**
 * (GeneralSignFiles)表服务实现类
 *
 * @author makejava
 * @since 2020-12-09 10:50:57
 */
@Service
@CrossOrigin
@Transactional(readOnly = false)
public class BackgroundImageFilesService extends CrudService<BackgroundImageFilesMapper, BackgroundImageFiles> {
    @Resource
    private BackgroundImageFilesMapper backgroundImageFilesMapper;


    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */

    public BackgroundImageFiles queryById(String id) {
        return this.backgroundImageFilesMapper.queryById(id);
    }

    /**
     * 分页数据
     * @return 对象列表
     */
    public Page<BackgroundImageFiles> findPage(Page<BackgroundImageFiles> page, BackgroundImageFiles backgroundImageFiles) {
        return super.findPage(page, backgroundImageFiles);
    }

    /**
     * 新增数据
     * @param  backgroundImageFiles 实例对象
     * @return 实例对象
     */
    public BackgroundImageFiles saveFile(BackgroundImageFiles backgroundImageFiles) {

        backgroundImageFiles.setId(IdGen.uuid());

        backgroundImageFiles.setUploadTime(new DateTime().toString("yyyy-MM-dd HH:mm:ss"));
        backgroundImageFilesMapper.insert(backgroundImageFiles);
        return backgroundImageFiles;
    }


    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    public boolean deleteById(String id) {
        return this.backgroundImageFilesMapper.deleteById(id) > 0;
    }

    public void update(BackgroundImageFiles backgroundImageFiles) {
        backgroundImageFilesMapper.update(backgroundImageFiles);
    }
}